﻿Public Class BlogDetails
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_Submit_Comment_Article_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Submit_Comment_Article.Click
        Dim _ArticleID As Integer = Request.QueryString("ID")
        Dim Uid As Integer
        Dim Uname As String = Page.User.Identity.Name
        Uid = CInt(userID(Uname))
        Dim sql As String = " INSERT INTO Blog_Comments (ArticleID, UserID, Comment_Article, Comment_Date ) VALUES (@v1, @v2, @v3, v4)"
        Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("UniConnectionString").ConnectionString)
        Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@v1", _ArticleID)
        cmd.Parameters.AddWithValue("@v2", Uid)
        cmd.Parameters.AddWithValue("@v3", Txt_Comment_Article.Text)
        cmd.Parameters.AddWithValue("@v4", Date.Today)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()
        Txt_Comment_Article.Text = String.Empty
        Response.Redirect("BlogDetails.aspx?ID=" & _ArticleID & "")
    End Sub
    Protected Function userID(ByVal uname As String) As Integer
        Dim uID As Integer
        Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("UniConnectionString").ConnectionString)
        conn.Open()
        Dim IDsql As String = " select aspnet_Users.UserId from aspnet_Users Where aspnet_Users.UserName = '" & uname & "'"
        Dim IDcmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(IDsql, conn)
        Dim Dreader As OleDb.OleDbDataReader
        Try
            Dreader = IDcmd.ExecuteReader()
            Dreader.Read()
            uID = Dreader("UserId")
        Catch
        End Try
        Return uID
        conn.Close()
        IDcmd.Dispose()
        conn.Dispose()
    End Function
End Class